<?php

namespace App\Models;

// use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel as Model;

class Payment extends Model
{

    protected $primaryKey = 'payment_id';

    protected $fillable = ['order_bn', 'pay_no', 'member_id', 'type', 'status', 'paid_amount', 'discount_amount', 'payment_code', 'pre_result', 'pay_result', 'pay_return', 'remark', 'created_at', 'updated_at'];

    protected $casts = [
        'created_at' => 'Y-m-d H:i:s',
        'updated_at' => 'Y-m-d H:i:s',
    ];

     protected $appends = ['payment_code_name'];

    /**
     * 会员信息
     * @return \Illuminate\Database\Eloquent\Relations\belongsTo
     */
    public function member()
    {
        return $this->belongsTo(Member::class, 'member_id');
    }

    public function getPaymentCodeNameAttribute()
    {
        $payment_arr = [
            'sumpay' => '统统付',
            'lianlianpay' => '连连付-小程序',
            'lianlpay_offline' => '连连付-线下',
        ];

        $paymentCodeName = '';
        if (isset($this->attributes['payment_code']) && $this->attributes['payment_code'])
        {
            $paymentCodeName = $payment_arr[$this->attributes['payment_code']] ?? '-';
        }
        return $paymentCodeName ?? '-';
    }

}
